package ntd.util;

import cn.hutool.core.util.StrUtil;
import redis.clients.jedis.Jedis;

/**
 * jedis 工具类
 */
public class UtilJedis extends Jedis {

    public UtilJedis(String url, Integer port, String password) {
        super(url, port);
        if (StrUtil.isNotBlank(password)) {
            super.auth(password); // 设置密码
        }
    }

    public boolean getLock(String key) {
        Long flag = this.setnx(key, "1");
        if (flag == 1) {
            this.expire(key, 10);
        }
        return flag == 1;
    }

    public void releaseLock(String key) {
        this.del(key);
    }
}
